package com.bkhech.bigdata.tiktok_anchor.videoinfo;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * 自定义数据类型
 * 主要是为了保存主播相关的核心字段，方便后期进行累加操作
 *
 * @author guowm
 * @date 2022/7/6
 */
public class VideoInfoWritable implements Writable {
    private long gold;
    private long watchNumPv;
    private long follower;
    private long length;

    public void set(long gold, long watchNumPv, long follower, long length) {
        this.gold = gold;
        this.watchNumPv = watchNumPv;
        this.follower = follower;
        this.length = length;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(gold);
        out.writeLong(watchNumPv);
        out.writeLong(follower);
        out.writeLong(length);
    }

    /**
     * readLong() 读取值顺序和 write 的顺序相对应
     *
     * @param in <code>DataInput</code> to deseriablize this object from.
     * @throws IOException
     */
    @Override
    public void readFields(DataInput in) throws IOException {
        this.gold = in.readLong();
        this.watchNumPv = in.readLong();
        this.follower = in.readLong();
        this.length = in.readLong();
    }

    public long getGold() {
        return gold;
    }

    public long getWatchNumPv() {
        return watchNumPv;
    }

    public long getFollower() {
        return follower;
    }

    public long getLength() {
        return length;
    }

    @Override
    public String toString() {
        return gold + "\t" + watchNumPv + "\t" + follower + "\t" + length;
    }
}
